/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.time.Month;
import java.time.Year;

/**
 * <p>Project: jse2303 - Switch2
 * <p>Powered by webrx On 2023-07-11 14:11:46
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Switch3 {
    public static void main(String[] args) {
        Year year = Year.of(2020);
        Month month = Month.of(2);
        int m = month.getValue();

        //switch 表达式 -> yield
        int days = switch (m) {
            case 4, 6, 9, 11 -> 30;
            case 2 -> year.isLeap() ? 29 : 28; //三元运算表达式

            //case 2 -> {
            //    if (year.isLeap()) {
            //        yield 29; //yield相当于表达式返回值
            //    } else {
            //        yield 28;
            //    }
            //}
            default -> 31;
        };
        System.out.printf("%d年%d月有%d天%n", year.getValue(), m, days);
    }
}
